package com.ctgu.computer.mapper;

import com.ctgu.computer.annotation.FillNowTime;
import com.ctgu.computer.domain.dto.TopicPageDTO;
import com.ctgu.computer.domain.po.*;
import com.ctgu.computer.domain.vo.TopicVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface TopicMapper {
    Page<TopicVO> page(TopicPageDTO topicPageDTO);

    @FillNowTime
    void insert(TextInfo textInfo);

    void insertSenderToTopic(SenderTextInfo senderTextInfo);

    void insertChannel(String channelName);

    @Select("select * from sender_text_info where text_id=#{textId}")
    SenderTextInfo selectTextToSenderByTextId(Integer textId);

    @Delete("delete from text_info where text_id=#{textId}")
    void deleteByTextId(Integer textId);

    @Delete("delete from sender_text_info where text_id=#{textId}")
    void deleteSenderToText(Integer textId);

    @Delete("delete from comment_text_sender_info where text_id=#{textId}")
    void deleteSenderToTextToComment(Integer textId);

    @Select("select * from channel_info")
    List<ChannelInfo> getAllChannel();

    @Select("select * from text_info where text_id =#{textId}")
    TextInfo selectById(Integer textId);

    @MapKey("textId")
    Map<Integer,SenderTextInfo> batchSelectSenderToTextByTextId(List<Integer> textIds);

    @Select("select * from channel_info where channel_id=#{channelId}")
    ChannelInfo selectChannelById(Integer channelId);

    List<CommentTextSenderInfo> batchSelectSenderToTextByToCommentTextId(List<Integer> taskIds);

    void update(TextInfo textInfo);

    @Select("select * from text_good_user where text_id=#{textId} and gooder_id=#{userId}")
    GoodText selectGoodTextByTextId(Integer textId,Integer userId);

    @FillNowTime
    void insertGoodText(GoodText goodText);

    @FillNowTime
    @Update("update text_good_user set is_good = #{isGood},create_time=#{createTime} " +
            "where text_id=#{textId} and gooder_id=#{gooderId} ")
    void updateGood(GoodText existedGoodText);

    @Delete("delete from text_good_user where gooder_id=#{userId} and text_id=#{textId}")
    void deleteGood(Integer textId, Integer userId);

    List<Integer> selectGoodTextBy(UserIdToTextIds userIdToTextIds);

    @Delete("delete from text_good_user where !is_good")
    void batchDeleteGood();
}
